package io.jboot.admin.service.provider;

import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import io.jboot.admin.service.api.VersionInfoService;
import io.jboot.admin.service.entity.model.VersionInfo;
import io.jboot.aop.annotation.Bean;
import io.jboot.components.rpc.annotation.RPCBean;
import io.jboot.db.model.Columns;
import io.jboot.service.JbootServiceBase;


@Bean
@RPCBean
public class VersionInfoServiceImpl extends JbootServiceBase<VersionInfo> implements VersionInfoService {

    @Override
    public Page<VersionInfo> findPage(VersionInfo search, int pageNumber, int pageSize) {
        Columns columns = Columns.create();
        if (StrKit.notBlank(search.getName())){
            columns.like("name",search.getName());
        }
        return DAO.paginateByColumns(pageNumber,pageSize,columns);
    }

    @Override
    public boolean delbatch(String[] ids) {
        return Db.tx(()->{
            for (String id:ids){
                if(!deleteById(id)){
                    return false;
                }
            }
            return true;
        });
    }

}
